<!DOCTYPE html>
<html lang="">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta itemprop="name" content="搭建vpn">
<meta itemprop="description" content="搭建vpn 作用：可以访问服务器的内网ip
目的：仅用于学习
操作对象：阿里云服务器
服务器内网ip：172.18.120.176
安装vpn之前：
步骤一：
在指定目录下创建docker-compose.yml文件和配置文件vpn.env
docker-compose.yml
version: &#39;3.7&#39;services:vpn:image: hwdsl2/ipsec-vpn-server:latestcontainer_name: vpnports:- 500:500/udp- 4500:4500/udprestart: alwaysenv_file:- ./vpn.envlogging:options:max-size: &#34;10M&#34;max-file: &#34;10&#34;privileged: truevpn.env
VPN_IPSEC_PSK=LZsRCfAfG3c#Y0X2 #共享密钥VPN_USER=nbiVPN_PASSWORD=yBBWlm7xgjSqh5IiVPN_ADDL_USERS=lican xiaoming #多个用户空格分隔VPN_ADDL_PASSWORDS=lican520 xiaoming520 #密码与账号对应VPN_DNS_SRV1=114.114.114.114VPN_DNS_SRV2=8.8.8.8步骤二：
启动docker-compose
docker-compose up -d;步骤三：
登录云服务器，修改安全组，配置500和4500端口，类型为udp
此时服务端的vpn已搭建完成
步骤四：
安装客户端，并配置
vpn-client-2.2.2-release.exe
配置详解
配置后使用vpn.env内配置的用户登录
成功之后就可以访问服务器的内网ip了">
<meta itemprop="datePublished" content="2024-11-15T10:40:23&#43;08:00" />
<meta itemprop="dateModified" content="2024-11-15T10:40:23&#43;08:00" />
<meta itemprop="wordCount" content="62">



<meta itemprop="keywords" content="" /><meta property="og:title" content="搭建vpn" />
<meta property="og:description" content="搭建vpn 作用：可以访问服务器的内网ip
目的：仅用于学习
操作对象：阿里云服务器
服务器内网ip：172.18.120.176
安装vpn之前：
步骤一：
在指定目录下创建docker-compose.yml文件和配置文件vpn.env
docker-compose.yml
version: &#39;3.7&#39;services:vpn:image: hwdsl2/ipsec-vpn-server:latestcontainer_name: vpnports:- 500:500/udp- 4500:4500/udprestart: alwaysenv_file:- ./vpn.envlogging:options:max-size: &#34;10M&#34;max-file: &#34;10&#34;privileged: truevpn.env
VPN_IPSEC_PSK=LZsRCfAfG3c#Y0X2 #共享密钥VPN_USER=nbiVPN_PASSWORD=yBBWlm7xgjSqh5IiVPN_ADDL_USERS=lican xiaoming #多个用户空格分隔VPN_ADDL_PASSWORDS=lican520 xiaoming520 #密码与账号对应VPN_DNS_SRV1=114.114.114.114VPN_DNS_SRV2=8.8.8.8步骤二：
启动docker-compose
docker-compose up -d;步骤三：
登录云服务器，修改安全组，配置500和4500端口，类型为udp
此时服务端的vpn已搭建完成
步骤四：
安装客户端，并配置
vpn-client-2.2.2-release.exe
配置详解
配置后使用vpn.env内配置的用户登录
成功之后就可以访问服务器的内网ip了" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.lican.site/postsbak/%E6%90%AD%E5%BB%BAvpn/" />
<meta property="article:published_time" content="2024-11-15T10:40:23+08:00" />
<meta property="article:modified_time" content="2024-11-15T10:40:23+08:00" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="搭建vpn"/>
<meta name="twitter:description" content="搭建vpn 作用：可以访问服务器的内网ip
目的：仅用于学习
操作对象：阿里云服务器
服务器内网ip：172.18.120.176
安装vpn之前：
步骤一：
在指定目录下创建docker-compose.yml文件和配置文件vpn.env
docker-compose.yml
version: &#39;3.7&#39;services:vpn:image: hwdsl2/ipsec-vpn-server:latestcontainer_name: vpnports:- 500:500/udp- 4500:4500/udprestart: alwaysenv_file:- ./vpn.envlogging:options:max-size: &#34;10M&#34;max-file: &#34;10&#34;privileged: truevpn.env
VPN_IPSEC_PSK=LZsRCfAfG3c#Y0X2 #共享密钥VPN_USER=nbiVPN_PASSWORD=yBBWlm7xgjSqh5IiVPN_ADDL_USERS=lican xiaoming #多个用户空格分隔VPN_ADDL_PASSWORDS=lican520 xiaoming520 #密码与账号对应VPN_DNS_SRV1=114.114.114.114VPN_DNS_SRV2=8.8.8.8步骤二：
启动docker-compose
docker-compose up -d;步骤三：
登录云服务器，修改安全组，配置500和4500端口，类型为udp
此时服务端的vpn已搭建完成
步骤四：
安装客户端，并配置
vpn-client-2.2.2-release.exe
配置详解
配置后使用vpn.env内配置的用户登录
成功之后就可以访问服务器的内网ip了"/>

	<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
	<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
	<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
	<link rel="manifest" href="/site.webmanifest">
	<link rel="mask-icon" href="/safari-pinned-tab.svg" color="">
	<link rel="shortcut icon" href="/favicon.ico">

	<title>搭建vpn</title>
	<link rel="stylesheet" href="https://www.lican.site/css/style.min.d3141168199607bf3a517216ce3c263814eecdbc8fca72a9a88700799a838219.css">
	
</head>

<body id="page">
	
	<header id="site-header" class="animated slideInUp faster">
		<div class="hdr-wrapper section-inner">
			<div class="hdr-left">
				<div class="site-branding">
					<a href="https://www.lican.site">花落雨忧</a>
				</div>
				<nav class="site-nav hide-in-mobile">
					<a href="https://www.lican.site/posts">首页</a>
					<a href="https://www.lican.site/tech/">技术文档</a>
					<a href="https://www.lican.site/article/">文章</a>
					<a href="https://www.lican.site/project/">项目</a>
					<a href="https://www.lican.site/about/">关于</a>
				</nav>
			</div>
			<div class="hdr-right hdr-icons">
				<button id="menu-btn" class="hdr-btn" title="Menu"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></button>
			</div>
		</div>
	</header>
	<div id="mobile-menu" class="animated fast">
		<ul>
			<li><a href="https://www.lican.site/posts">首页</a></li>
			<li><a href="https://www.lican.site/tech/">技术文档</a></li>
			<li><a href="https://www.lican.site/article/">文章</a></li>
			<li><a href="https://www.lican.site/project/">项目</a></li>
			<li><a href="https://www.lican.site/about/">关于</a></li>
		</ul>
	</div>


	<main class="site-main section-inner thin animated fadeIn faster">
		<h1>搭建vpn</h1>
		<div class="content">
			<h3 id="搭建vpn">搭建vpn<a href="#搭建vpn" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg></a></h3>
<p>作用：可以访问服务器的内网ip</p>
<p>目的：仅用于学习</p>
<p>操作对象：阿里云服务器</p>
<p>服务器内网ip：172.18.120.176</p>
<p>安装vpn之前：</p>
<p><img src="https://www.lican.site/images/vpn/1731568658726.png" alt="1731568658726"></p>
<p>步骤一：</p>
<p>在指定目录下创建docker-compose.yml文件和配置文件vpn.env</p>
<p><img src="https://www.lican.site/images/vpn/1731568802257.png" alt="1731568802257"></p>
<p>docker-compose.yml</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#a6e22e">version</span>: <span style="color:#960050;background-color:#1e0010">&#39;</span><span style="color:#ae81ff">3.7</span><span style="color:#960050;background-color:#1e0010">&#39;</span>
<span style="color:#a6e22e">services</span>:
  <span style="color:#a6e22e">vpn</span>:
     <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">hwdsl2</span><span style="color:#f92672">/</span><span style="color:#a6e22e">ipsec</span><span style="color:#f92672">-</span><span style="color:#a6e22e">vpn</span><span style="color:#f92672">-</span><span style="color:#a6e22e">server</span>:<span style="color:#a6e22e">latest</span>
     <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">vpn</span>
     <span style="color:#a6e22e">ports</span>:
       <span style="color:#f92672">-</span> <span style="color:#ae81ff">500</span>:<span style="color:#ae81ff">500</span><span style="color:#f92672">/</span><span style="color:#a6e22e">udp</span>
       <span style="color:#f92672">-</span> <span style="color:#ae81ff">4500</span>:<span style="color:#ae81ff">4500</span><span style="color:#f92672">/</span><span style="color:#a6e22e">udp</span>
     <span style="color:#a6e22e">restart</span>: <span style="color:#a6e22e">always</span>
     <span style="color:#a6e22e">env_file</span>:
       <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">vpn</span>.<span style="color:#a6e22e">env</span>
     <span style="color:#a6e22e">logging</span>:
       <span style="color:#a6e22e">options</span>:
         <span style="color:#a6e22e">max</span><span style="color:#f92672">-</span><span style="color:#a6e22e">size</span>: <span style="color:#e6db74">&#34;10M&#34;</span>
         <span style="color:#a6e22e">max</span><span style="color:#f92672">-</span><span style="color:#a6e22e">file</span>: <span style="color:#e6db74">&#34;10&#34;</span>
     <span style="color:#a6e22e">privileged</span>:  <span style="color:#66d9ef">true</span>

</code></pre></div><p>vpn.env</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#a6e22e">VPN_IPSEC_PSK</span>=<span style="color:#a6e22e">LZsRCfAfG3c</span><span style="color:#960050;background-color:#1e0010">#</span><span style="color:#a6e22e">Y0X2</span> <span style="color:#960050;background-color:#1e0010">#</span><span style="color:#a6e22e">共享密钥</span>
<span style="color:#a6e22e">VPN_USER</span>=<span style="color:#a6e22e">nbi</span>
<span style="color:#a6e22e">VPN_PASSWORD</span>=<span style="color:#a6e22e">yBBWlm7xgjSqh5Ii</span>

<span style="color:#a6e22e">VPN_ADDL_USERS</span>=<span style="color:#a6e22e">lican</span> <span style="color:#a6e22e">xiaoming</span> <span style="color:#960050;background-color:#1e0010">#</span><span style="color:#a6e22e">多个用户空格分隔</span>
<span style="color:#a6e22e">VPN_ADDL_PASSWORDS</span>=<span style="color:#a6e22e">lican520</span> <span style="color:#a6e22e">xiaoming520</span> <span style="color:#960050;background-color:#1e0010">#</span><span style="color:#a6e22e">密码与账号对应</span>

<span style="color:#a6e22e">VPN_DNS_SRV1</span>=<span style="color:#ae81ff">114.114.114.114</span>
<span style="color:#a6e22e">VPN_DNS_SRV2</span>=<span style="color:#ae81ff">8.8.8.8</span>

</code></pre></div><p>步骤二：</p>
<p>启动docker-compose</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">compose</span> <span style="color:#a6e22e">up</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">d</span>;
</code></pre></div><p><img src="https://www.lican.site/images/vpn/1731572180933.png" alt="1731572180933"></p>
<p>步骤三：</p>
<p>登录云服务器，修改安全组，配置500和4500端口，类型为udp</p>
<p><img src="https://www.lican.site/images/vpn/1731572259429.png" alt="1731572259429"></p>
<p>此时服务端的vpn已搭建完成</p>
<p>步骤四：</p>
<p>安装客户端，并配置</p>
<p><a href="https://www.lican.site/images/vpn/vpn-client-2.2.2-release.exe">vpn-client-2.2.2-release.exe</a></p>
<p><img src="https://www.lican.site/images/vpn/1731577288327.png" alt="1731577288327"></p>
<p><a href="https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/docs/clients-xauth-zh.md">配置详解</a></p>
<p><img src="https://www.lican.site/images/vpn/1731577400079.png" alt="1731577400079"></p>
<p>配置后使用vpn.env内配置的用户登录</p>
<p><img src="https://www.lican.site/images/vpn/1731577606956.png" alt="1731577606956"></p>
<p>成功之后就可以访问服务器的内网ip了</p>
<p><img src="https://www.lican.site/images/vpn/1731577653041.png" alt="1731577653041"></p>

		</div>
	</main>

	<footer id="site-footer" class="section-inner thin animated fadeIn faster">
		<p>&copy; 2024 <a href="https://www.lican.site"></a></p>
		<p>
			Made with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> &#183; Theme <a href="https://github.com/Track3/hermit" target="_blank" rel="noopener">Hermit</a> &#183; <a href="https://www.lican.site/post/index.xml" target="_blank" title="rss"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-rss"><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg></a>
		</p>
	</footer>


	<script src="https://www.lican.site/js/main.min.784417f5847151f848c339cf0acb13a06cbb648b1483435a28ed4556c4ead69b.js"></script>

</body>

</html>
